﻿package com.controller;

import java.io.File;
import java.io.IOException;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.entity.Baomingjilu;
import com.server.BaomingjiluServer;
import com.util.PageBean;
import net.sf.json.JSONObject;
import com.util.db;
import java.sql.SQLException;
import java.sql.*;
@Controller
public class BaomingjiluController {
	@Resource
	private BaomingjiluServer baomingjiluService;


   
	@RequestMapping("addBaomingjilu.do")
	public String addBaomingjilu(HttpServletRequest request,Baomingjilu baomingjilu,HttpSession session) throws SQLException{
		Timestamp time=new Timestamp(System.currentTimeMillis());
		
		baomingjilu.setAddtime(time.toString().substring(0, 19));
		baomingjiluService.add(baomingjilu);
		session.setAttribute("backxx", "添加成功");
		session.setAttribute("backurl", request.getHeader("Referer"));
		
		//session.setAttribute("backurl", "baomingjiluList.do");
		
		return "redirect:postback.jsp";
		//return "redirect:baomingjiluList.do";
		
		
		
	}
 
//	处理编辑
	@RequestMapping("doUpdateBaomingjilu.do")
	public String doUpdateBaomingjilu(int id,ModelMap map,Baomingjilu baomingjilu){
		baomingjilu=baomingjiluService.getById(id);
		map.put("baomingjilu", baomingjilu);
		return "baomingjilu_updt";
	}
	
	
	
	
	
//	后台详细
	@RequestMapping("baomingjiluDetail.do")
	public String baomingjiluDetail(int id,ModelMap map,Baomingjilu baomingjilu){
		baomingjilu=baomingjiluService.getById(id);
		map.put("baomingjilu", baomingjilu);
		return "baomingjilu_detail";
	}
//	前台详细
	@RequestMapping("bmjlDetail.do")
	public String bmjlDetail(int id,ModelMap map,Baomingjilu baomingjilu){
		baomingjilu=baomingjiluService.getById(id);
		map.put("baomingjilu", baomingjilu);
		return "baomingjiludetail";
	}
//	
	@RequestMapping("updateBaomingjilu.do")
	public String updateBaomingjilu(int id,ModelMap map,Baomingjilu baomingjilu,HttpServletRequest request,HttpSession session){
		baomingjiluService.update(baomingjilu);
		session.setAttribute("backxx", "修改成功");
		session.setAttribute("backurl", request.getHeader("Referer"));
		return "redirect:postback.jsp";
		//String url = request.getHeader("Referer");
		//return "redirect:"+url;
		//return "redirect:baomingjiluList.do";
	}

//	分页查询
	@RequestMapping("baomingjiluList.do")
	public String baomingjiluList(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Baomingjilu baomingjilu, String xianlubianhao, String xianlumingcheng, String mubiaojingdian, String chufachengshi, String chuxingshijian, String lvyougongsi, String xianlubaojia, String chuxingrenshu1,String chuxingrenshu2, String xingchengfeiyong, String beizhu, String baomingren, String issh, String iszf){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 15);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 15);
		
		
		if(xianlubianhao==null||xianlubianhao.equals("")){pmap.put("xianlubianhao", null);}else{pmap.put("xianlubianhao", xianlubianhao);}
		if(xianlumingcheng==null||xianlumingcheng.equals("")){pmap.put("xianlumingcheng", null);}else{pmap.put("xianlumingcheng", xianlumingcheng);}
		if(mubiaojingdian==null||mubiaojingdian.equals("")){pmap.put("mubiaojingdian", null);}else{pmap.put("mubiaojingdian", mubiaojingdian);}
		if(chufachengshi==null||chufachengshi.equals("")){pmap.put("chufachengshi", null);}else{pmap.put("chufachengshi", chufachengshi);}
		if(chuxingshijian==null||chuxingshijian.equals("")){pmap.put("chuxingshijian", null);}else{pmap.put("chuxingshijian", chuxingshijian);}
		if(lvyougongsi==null||lvyougongsi.equals("")){pmap.put("lvyougongsi", null);}else{pmap.put("lvyougongsi", lvyougongsi);}
		if(xianlubaojia==null||xianlubaojia.equals("")){pmap.put("xianlubaojia", null);}else{pmap.put("xianlubaojia", xianlubaojia);}
		if(chuxingrenshu1==null||chuxingrenshu1.equals("")){pmap.put("chuxingrenshu1", null);}else{pmap.put("chuxingrenshu1", chuxingrenshu1);}
		if(chuxingrenshu2==null||chuxingrenshu2.equals("")){pmap.put("chuxingrenshu2", null);}else{pmap.put("chuxingrenshu2", chuxingrenshu2);}
		if(xingchengfeiyong==null||xingchengfeiyong.equals("")){pmap.put("xingchengfeiyong", null);}else{pmap.put("xingchengfeiyong", xingchengfeiyong);}
		if(beizhu==null||beizhu.equals("")){pmap.put("beizhu", null);}else{pmap.put("beizhu", beizhu);}
		if(baomingren==null||baomingren.equals("")){pmap.put("baomingren", null);}else{pmap.put("baomingren", baomingren);}
		
		int total=baomingjiluService.getCount(pmap);
		pageBean.setTotal(total);
		List<Baomingjilu> list=baomingjiluService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "baomingjilu_list";
	}
	
	@RequestMapping("baomingjiluList3.do")
	public String baomingjiluList3(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Baomingjilu baomingjilu, String xianlubianhao, String xianlumingcheng, String mubiaojingdian, String chufachengshi, String chuxingshijian, String lvyougongsi, String xianlubaojia, String chuxingrenshu1,String chuxingrenshu2, String xingchengfeiyong, String beizhu, String baomingren, String issh, String iszf,HttpServletRequest request){
		/*if(session.getAttribute("user")==null){
			return "login";
		}*/
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 15);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 15);
		
		pmap.put("lvyougongsi", (String)request.getSession().getAttribute("username"));
		if(xianlubianhao==null||xianlubianhao.equals("")){pmap.put("xianlubianhao", null);}else{pmap.put("xianlubianhao", xianlubianhao);}
		if(xianlumingcheng==null||xianlumingcheng.equals("")){pmap.put("xianlumingcheng", null);}else{pmap.put("xianlumingcheng", xianlumingcheng);}
		if(mubiaojingdian==null||mubiaojingdian.equals("")){pmap.put("mubiaojingdian", null);}else{pmap.put("mubiaojingdian", mubiaojingdian);}
		if(chufachengshi==null||chufachengshi.equals("")){pmap.put("chufachengshi", null);}else{pmap.put("chufachengshi", chufachengshi);}
		if(chuxingshijian==null||chuxingshijian.equals("")){pmap.put("chuxingshijian", null);}else{pmap.put("chuxingshijian", chuxingshijian);}
		if(xianlubaojia==null||xianlubaojia.equals("")){pmap.put("xianlubaojia", null);}else{pmap.put("xianlubaojia", xianlubaojia);}
		if(chuxingrenshu1==null||chuxingrenshu1.equals("")){pmap.put("chuxingrenshu1", null);}else{pmap.put("chuxingrenshu1", chuxingrenshu1);}
		if(chuxingrenshu2==null||chuxingrenshu2.equals("")){pmap.put("chuxingrenshu2", null);}else{pmap.put("chuxingrenshu2", chuxingrenshu2);}
		if(xingchengfeiyong==null||xingchengfeiyong.equals("")){pmap.put("xingchengfeiyong", null);}else{pmap.put("xingchengfeiyong", xingchengfeiyong);}
		if(beizhu==null||beizhu.equals("")){pmap.put("beizhu", null);}else{pmap.put("beizhu", beizhu);}
		
		
		int total=baomingjiluService.getCount(pmap);
		pageBean.setTotal(total);
		List<Baomingjilu> list=baomingjiluService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "baomingjilu_list3";
	}
	@RequestMapping("baomingjiluList2.do")
	public String baomingjiluList2(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Baomingjilu baomingjilu, String xianlubianhao, String xianlumingcheng, String mubiaojingdian, String chufachengshi, String chuxingshijian, String lvyougongsi, String xianlubaojia, String chuxingrenshu1,String chuxingrenshu2, String xingchengfeiyong, String beizhu, String baomingren, String issh, String iszf,HttpServletRequest request){
		/*if(session.getAttribute("user")==null){
			return "login";
		}*/
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 15);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 15);
		
		pmap.put("baomingren", (String)request.getSession().getAttribute("username"));
		if(xianlubianhao==null||xianlubianhao.equals("")){pmap.put("xianlubianhao", null);}else{pmap.put("xianlubianhao", xianlubianhao);}
		if(xianlumingcheng==null||xianlumingcheng.equals("")){pmap.put("xianlumingcheng", null);}else{pmap.put("xianlumingcheng", xianlumingcheng);}
		if(mubiaojingdian==null||mubiaojingdian.equals("")){pmap.put("mubiaojingdian", null);}else{pmap.put("mubiaojingdian", mubiaojingdian);}
		if(chufachengshi==null||chufachengshi.equals("")){pmap.put("chufachengshi", null);}else{pmap.put("chufachengshi", chufachengshi);}
		if(chuxingshijian==null||chuxingshijian.equals("")){pmap.put("chuxingshijian", null);}else{pmap.put("chuxingshijian", chuxingshijian);}
		if(xianlubaojia==null||xianlubaojia.equals("")){pmap.put("xianlubaojia", null);}else{pmap.put("xianlubaojia", xianlubaojia);}
		if(chuxingrenshu1==null||chuxingrenshu1.equals("")){pmap.put("chuxingrenshu1", null);}else{pmap.put("chuxingrenshu1", chuxingrenshu1);}
		if(chuxingrenshu2==null||chuxingrenshu2.equals("")){pmap.put("chuxingrenshu2", null);}else{pmap.put("chuxingrenshu2", chuxingrenshu2);}
		if(xingchengfeiyong==null||xingchengfeiyong.equals("")){pmap.put("xingchengfeiyong", null);}else{pmap.put("xingchengfeiyong", xingchengfeiyong);}
		if(beizhu==null||beizhu.equals("")){pmap.put("beizhu", null);}else{pmap.put("beizhu", beizhu);}
		
		
		int total=baomingjiluService.getCount(pmap);
		pageBean.setTotal(total);
		List<Baomingjilu> list=baomingjiluService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "baomingjilu_list2";
	}
	
	
	@RequestMapping("bmjlList.do")
	public String bmjlList(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Baomingjilu baomingjilu, String xianlubianhao, String xianlumingcheng, String mubiaojingdian, String chufachengshi, String chuxingshijian, String lvyougongsi, String xianlubaojia, String chuxingrenshu1,String chuxingrenshu2, String xingchengfeiyong, String beizhu, String baomingren, String issh, String iszf){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 15);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 15);
		
		
		if(xianlubianhao==null||xianlubianhao.equals("")){pmap.put("xianlubianhao", null);}else{pmap.put("xianlubianhao", xianlubianhao);}
		if(xianlumingcheng==null||xianlumingcheng.equals("")){pmap.put("xianlumingcheng", null);}else{pmap.put("xianlumingcheng", xianlumingcheng);}
		if(mubiaojingdian==null||mubiaojingdian.equals("")){pmap.put("mubiaojingdian", null);}else{pmap.put("mubiaojingdian", mubiaojingdian);}
		if(chufachengshi==null||chufachengshi.equals("")){pmap.put("chufachengshi", null);}else{pmap.put("chufachengshi", chufachengshi);}
		if(chuxingshijian==null||chuxingshijian.equals("")){pmap.put("chuxingshijian", null);}else{pmap.put("chuxingshijian", chuxingshijian);}
		if(lvyougongsi==null||lvyougongsi.equals("")){pmap.put("lvyougongsi", null);}else{pmap.put("lvyougongsi", lvyougongsi);}
		if(xianlubaojia==null||xianlubaojia.equals("")){pmap.put("xianlubaojia", null);}else{pmap.put("xianlubaojia", xianlubaojia);}
		if(chuxingrenshu1==null||chuxingrenshu1.equals("")){pmap.put("chuxingrenshu1", null);}else{pmap.put("chuxingrenshu1", chuxingrenshu1);}
		if(chuxingrenshu2==null||chuxingrenshu2.equals("")){pmap.put("chuxingrenshu2", null);}else{pmap.put("chuxingrenshu2", chuxingrenshu2);}
		if(xingchengfeiyong==null||xingchengfeiyong.equals("")){pmap.put("xingchengfeiyong", null);}else{pmap.put("xingchengfeiyong", xingchengfeiyong);}
		if(beizhu==null||beizhu.equals("")){pmap.put("beizhu", null);}else{pmap.put("beizhu", beizhu);}
		if(baomingren==null||baomingren.equals("")){pmap.put("baomingren", null);}else{pmap.put("baomingren", baomingren);}
		
		int total=baomingjiluService.getCount(pmap);
		pageBean.setTotal(total);
		List<Baomingjilu> list=baomingjiluService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "baomingjilulist";
	}
	
	@RequestMapping("deleteBaomingjilu.do")
	public String deleteBaomingjilu(int id,HttpServletRequest request){
		baomingjiluService.delete(id);
		String url = request.getHeader("Referer");
		return "redirect:"+url;
		//return "redirect:baomingjiluList.do";
	}
	
	
}
